import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.InputMismatchException;

/**
 * @author Egor Kulikov (egor@egork.net)
 */
public class Horrible {
	@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
	InputReader in;
	PrintWriter out;
	private int[] l, r;
	private long[] v, s;

	void solve() {
		int n = in.readInt();
		l = new int[4 * n];
		r = new int[4 * n];
		v = new long[4 * n];
		s = new long[4 * n];
		initTree(0, n, 0);
		int c = in.readInt();
		for (int i = 0; i < c; i++) {
			if (in.readInt() == 0) {
				int p = in.readInt() - 1;
				int q = in.readInt();
				add(p, q, in.readInt(), 0);
			} else {
				int p = in.readInt() - 1;
				int q = in.readInt();
				out.println(get(p, q, 0));
			}
		}
	}

	private long get(int p, int q, int root) {
		if (p >= r[root] || q <= l[root])
			return 0;
		if (p <= l[root] && q >= r[root]) {
			return s[root];
		}
		int mult;
		if (l[root] <= p && r[root] >= q)
			mult = q - p;
		else if (l[root] > p)
			mult = q - l[root];
		else
			mult = r[root] - p;
		return get(p, q, 2 * root + 1) + get(p, q, 2 * root + 2) + v[root] * mult;
	}

	private void add(int p, int q, long value, int root) {
		if (p >= r[root] || q <= l[root])
			return;
		if (p <= l[root] && q >= r[root]) {
			v[root] += value;
			s[root] += value * (r[root] - l[root]);
			return;
		}
		if (l[root] <= p && r[root] >= q)
			s[root] += value * (q - p);
		else if (l[root] > p)
			s[root] += value * (q - l[root]);
		else
			s[root] += value * (r[root] - p);
		add(p, q, value, 2 * root + 1);
		add(p, q, value, 2 * root + 2);
	}

	private void initTree(int left, int right, int root) {
		l[root] = left;
		r[root] = right;
		if (right - left > 1) {
			initTree(left, (left + right) / 2, 2 * root + 1);
			initTree((left + right) / 2, right, 2 * root + 2);
		}
	}

	public static void main(String[] args) {
		new Horrible().run();
	}

	Horrible() {
		@SuppressWarnings({"UnusedDeclaration"})
		String id = getClass().getName().toLowerCase();
		//noinspection EmptyTryBlock
		try {
//			System.setIn(new FileInputStream(id + ".in"));
//			System.setOut(new PrintStream(new FileOutputStream(id + ".out")));
//			System.setIn(new FileInputStream("input.txt"));
//			System.setOut(new PrintStream(new FileOutputStream("output.txt")));
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
	}

	void run() {
		//noinspection InfiniteLoopStatement
		int t = in.readInt();
		for (int i = 0; i < t; i++)
			solve();
		exit();
	}

	@SuppressWarnings({"UnusedDeclaration"})
	void exit() {
		out.close();
		System.exit(0);
	}

	@SuppressWarnings({"UnusedDeclaration"})
	static class InputReader {
		InputStream stream;
		byte[] buf = new byte[1024];
		int curChar, numChars;

		InputReader(InputStream stream) {
			this.stream = stream;
		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		BigInteger readBigInteger() {
			try {
				return new BigInteger(readString());
			} catch (NumberFormatException e) {
				throw new InputMismatchException();
			}
		}

		char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}
	}
}
